package wowraidmanager.server.controller.cron.wishlist.user;

import java.util.ArrayList;
import java.util.Date;

import org.slim3.controller.Controller;
import org.slim3.controller.Navigation;

import wowraidmanager.server.service.wishlist.MemberBackupServiceImpl;
import wowraidmanager.server.service.wishlist.MemberServiceImpl;
import wowraidmanager.server.service.wishlist.contact.ContactServiceImpl;
import wowraidmanager.shared.model.wishlist.Member;
import wowraidmanager.shared.model.wishlist.MemberBackup;

public class MemberBackupController extends Controller {

    protected MemberServiceImpl memberService = new MemberServiceImpl();

    protected MemberBackupServiceImpl memberBackupService = new MemberBackupServiceImpl();

    protected ContactServiceImpl contactService = new ContactServiceImpl();

    ArrayList<MemberBackup> memberBackupList = new ArrayList<MemberBackup>();

    @Override
    public Navigation run() throws Exception {

        getAllmember();

        return null;
    }

    private void getAllmember(){
        setMemberBackup(memberService.getAllMember());
        memberBackupService.setMemberBackup(memberBackupList);
        memberBackupService.deleteMemberBackup();

    }

    protected void setMemberBackup(ArrayList<Member> result){
        for(Member member:result){
            MemberBackup memberBackup = new MemberBackup();

            memberBackup.setMemberName(member.getMemberName());
            memberBackup.setMemberAccount(member.getMemberAccount());
            memberBackup.setMembertype(member.getMembertype());
            memberBackup.setGuild(member.getGuild());
            memberBackup.setOrder(member.getOrder());
            memberBackup.setRealm(member.getRealm());
            memberBackup.setWishlist(member.getWishlist());

            memberBackup.setBackupDate(new Date());
            memberBackup.setBackupKey(member.getKey());
            memberBackup.setBackupVersion(member.getVersion());

            memberBackupList.add(memberBackup);
        }

    }
}
